/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ChartWindow.java
 *
 * Created on 2010-02-14, 23:05:06
 */
package desktopapplication2;

import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Hashtable;
import marcin.belzowski.geoMap.Queries;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author marcin
 */
public class ChartWindow extends javax.swing.JDialog {

    /** Creates new form ChartWindow */
    public ChartWindow(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        find();
        initChart();
       
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N
        getContentPane().setLayout(new java.awt.FlowLayout());

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void initChart() {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for(String name : ht.keySet()){
            dataset.addValue(ht.get(name),"Streets", name);

        }
//dataset.addValue(1.0, "Row 1", "Column 1");
//dataset.addValue(5.0, "Row 1", "Column 2");
//dataset.addValue(3.0, "Row 1", "Column 3");
//dataset.addValue(2.0, "Row 2", "Column 1");
//dataset.addValue(3.0, "Row 2", "Column 2");
//dataset.addValue(2.0, "Row 2", "Column 3");
JFreeChart chart = ChartFactory.createBarChart(
"Frequency Chart", // chart title
"Streets Name", // domain axis label
"cars / hours", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips?
false // URLs?
);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(500, 270));
        chartPanel.setVisible(true);
        setContentPane(chartPanel);
        
       pack();
        
    }
    private void find() {
        queries = new Queries();
        streets = queries.getStreets();
        ht = queries.findFrequencyforAll(streets);
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                ChartWindow dialog = new ChartWindow(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    
    private Queries queries;
    ArrayList<String> streets;
    Hashtable<String, Double> ht;

}
